package Encoder;


/**
 * Title:        ImageRuntimeException<br>
 * Description:  The class for runtime-exceptions proper to image processing.<br>
 * @author Randr
 * 
 */
public class ImageRuntimeException extends RuntimeException {

    /**
     * Threw by all methods where is attempted to open a file.
     */
    public static int failedToOpenCode = 310;
    /**
     * Threw by all methods where is attempted to open a file.
     */
    public static String failedToOpenMsg =
            "Failed to open given file.";

    /**
     * Threw by all methods where is attempted to read from a file.
     */
    public static int failedToReadCode = 311;
    /**
     * Threw by all methods where is attempted to read from a file.
     */
    public static String failedToReadMsg =
            "Failed to read from given file.";

    /**
     * Threw by all methods where is attempted to close a file.
     */
    public static int failedToCloseCode = 313;
    /**
     * Threw by all methods where is attempted to close a file.
     */
    public static String failedToCloseMsg =
            "Failed to close the given file.";

    /**
     * Threw by all methods where is attempted to read from a file.
     * Specially JpegEncoder that writes into stream
     */
    public static int failedToWriteCode = 312;
    /**
     * Threw by all methods where is attempted to read from a file.
     * Specially JpegEncoder that writes into stream
     */
    public static String failedToWriteMsg =
            "Failed to write into the given file.";

    /**
     * Threw by all methods where is attempted to decompress ZIP format.
     * Specially TffDecoder
     */
    public static int failedToDecompressZipFormatCode = 313;
    /**
     * Threw by all methods where is attempted to decompress ZIP format.
     * Specially TffDecoder
     */
    public static String failedToDecompressZipFormatMsg =
            "Failed to uncompress from ZIP format";

    /**
     * Threw by all methods where is attempted to compress into ZIP format.
     * Specially TffDecoder
     */
    public static int failedToCompressZipFormatCode = 314;
    /**
     * Threw by all methods where is attempted to compress into ZIP format.
     * Specially TffDecoder
     */
    public static String failedToCompressZipFormatMsg =
            "Failed to uncompress from ZIP format";

    /**
     * The code of the error.
     */
    private int errorCode;

    /**
     * The first constructor.<br>
     * Throws a runtime-exception.
     * @param msg A image-processing-error-message.
     * @param errorNumber A image-processing-error-number
     */
    public ImageRuntimeException(String msg, int errorNumber) {
        super(msg);
        this.errorCode = errorNumber;
        this.intoLog();
    }

    /**
     * Gets the image-processing-error-number.
     * @return An integer type representing the image-processing-error-number
     */
    public int getErrorCode() {
        return this.errorCode;
    }

    /**
     * Write code and message into the log file or System err.
     */
    private void intoLog() {
        //Category cat=Category.getRoot();
//    Enumeration enum=cat.getAllAppenders();
//    if (enum.hasMoreElements() && cat.isEnabledFor(Priority.ERROR))
//    {
//      cat.error("\n"+"Image-processing runtime exception code "+this.errorCode,this);
//    }
//    else
//    {
//      System.err.println("\n"+"Image-processing runtime exception code "+this.errorCode);
//      this.printStackTrace(System.err);
//    }
    }
}
